<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/19
 * Time: 23:13
 */

namespace app\common\model;




class Category extends Base
{
    public function add($data) {
        $data['status'] = 1;
        $res = $this->save($data);
        return $res;
    }

    /*
     * 获取正常一级栏目，parent_id=0，status=1,注意不要漏status=1
     */
    public function getNormalFirstCategory() {
        $data = [
            'status' => 1,
            'parent_id'=>0
        ];
        $order = [
            'id' => 'desc',
        ];

        return $this->where($data)
            ->order($order)
            ->select();
    }

    /*
     * 获取一级分类
     */
    public function getFirstCategorys($parentId=0)
    {
        $data = [
            'status' => ['neq',-1],
            'parent_id'=>$parentId
        ];
        $order = [
            'id' => 'desc',
            'listorder'=>'desc'
        ];
        return $this->where($data)
            ->order($order)
            ->select();
    }

    /**
     * 获取分类数据
     */
    public function getNormalCategoryByParentId($parentId=0)
    {
        $data = [
            'status' => 1,
            'parent_id' => $parentId,
        ];

        $order = [
            'id' => 'desc',
        ];

        return $this->where($data)
            ->order($order)
            ->select();
    }

}